package com.bw.domain;

import com.bw.util.UserLoginValid;
import com.bw.util.UserRegValid;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Future;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Pattern;
import java.util.Date;

public class User {
    private  Integer id;
    @NotBlank(message = "用户名不能为空",groups = {UserLoginValid.class,UserRegValid.class})
    private String username;
    @Pattern(regexp = "(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z]).{6,10}",message = "密码必须包含大小字母和数字并且是6-10",groups = {UserRegValid.class})
    @NotBlank(message = "密码不能为空",groups = {UserLoginValid.class,UserRegValid.class})
    private String password;
    //手机的号规则
    @NotBlank(message = "手机不能为空" ,groups = {UserRegValid.class})
    private String phone;
    //邮箱的规则  @Email

    @NotBlank(message = "邮箱不能为空",groups = {UserRegValid.class})
    private String  email;
    @NotNull(message = "性别必须选择",groups = {UserRegValid.class})
    private Gender gender;

    @NotNull(message = "生日必须选择",groups = {UserRegValid.class})
    @Past(message = "日期必须是小于今天的",groups = {UserRegValid.class})
    //@Future(message = "日期必须是大于今天的",groups = {UserRegValid.class})
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birth;



    public Date getBirth() {
        return birth;
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", phone='" + phone + '\'' +
                ", email='" + email + '\'' +
                '}';
    }
}
